#如：深圳竞价
#给 PROJName 赋值为 VMarket_SZSE_Binary_Mock
#同时给 SLNName 赋值上级目录 VMarket_SZSE_Binary_inversion_1921_redis

#根路径
OBJRootPath = /home/lighthouse/hrfy
#工程上级目录名称
SLNName = VMarket_SHSE_JJ_MQ_1920
#工程名称
PROJName = VMarket_SHSE_JJ_MQ

#目标名称
TARGET = $(PROJName)

#工程上级目录
SLNPATH = $(OBJRootPath)/$(SLNName)

#目标目录
WORK_PATHROOT := $(OBJRootPath)/makefile

#源代码目录
SRC_PATH = $(SLNPATH)/$(PROJName)
#生成的执行文件目录
EXE_PATH = $(WORK_PATHROOT)/$(TARGET)
#生成的中间文件目录
OBJ_PATH = $(WORK_PATHROOT)/$(TARGET)/obj
#第三方链接库目录（so所在目录）
LIB_PATH := $(SLNPATH)/lib

#获取源代码目录下的所有C源文件
SRCs_C = $(wildcard $(SRC_PATH)/*.c)
Targets_C = $(patsubst %.c, %, $(SRCs_C))

#获取源代码目录下的C++源文件
SRCs_CPP = $(wildcard $(SRC_PATH)/*.cpp)
Targets_CPP = $(patsubst %.cpp, %, $(SRCs_CPP))

#获取第三方链接库目录下的库文件
LIB_PRE := lib
LIB_EXT := .so
SRC_LIB = $(wildcard $(LIB_PATH)/*$(LIB_EXT))
#LIBS_4LINK2 := $(patsubst %$(LIB_EXT), %, $(SRC_LIB))
#LIBS_4LINK := $(SRC_LIB:$(LIB_PRE)%$(LIB_EXT)=-l%)

LIBS_4LINK = -lboost_date_time \
-lboost_regex \
-lboost_program_options \
-lboost_system \
-lboost_filesystem \
-lboost_log \
-lboost_log_setup \
-lboost_chrono \
-lboost_thread \
-lpthread \
-lhiredis -lrabbitmq #-ltbb -lboost_atomic

LIBS_4LINK2 = \
-lboost_atomic \
-lboost_thread \
-lboost_log \
-lboost_system \
-lboost_filesystem \
-lboost_regex \
-lpthread \
-lhiredis -lrabbitmq #-ltbb -lthread_db \

LIBS_4LINK3 = \
-lboost_atomic \
-lboost_thread \
-lboost_system \
-lboost_filesystem \
-lboost_regex \
-lpthread \
-lhiredis -lrabbitmq #-ltbb -lthread_db \

LIB_PATH_4LINK=-L/usr/local/include/boost/lib -L/opt/glibc-2.17-build/nptl_db #-L $(LIB_PATH) -L $(WORK_PATHROOT)/boost/lib -L /usr/local/lib

#INCLUDES=-I/usr/local/include -I$(SRC_PATH)
#LIBS=-L/usr/local/lib -lboost_log -lboost_log_setup -lboost_thread -lboost_system -lrt -lpthread -lopencv_core -lopencv_highgui -lopencv_imgproc


#中间文件集合
Objects = $(SRCs_C:$(SRC_PATH)/%.c=$(OBJ_PATH)/%_c.o) $(SRCs_CPP:$(SRC_PATH)/%.cpp=$(OBJ_PATH)/%_cpp.o) #$(OBJ_PATH)/redis_ccpp.o

BOOST_ROOT = /opt/boost_1_62_0

$(warning $(BOOST_ROOT) 1 ${_boost_DEBUG_NAMES} 2 ${BOOST_LIB_DIAGNOSTIC})

GCPPLink = g++
GCPP = gcc

INCLUDEFlags = -I/usr/local/include/boost/include -I$(SRC_PATH) # -I /usr/include/sys
CFLAGS = -g -O -std=c++11 -Wall -lm #-lgcc_s -lc

$(EXE_PATH)/$(TARGET): $(Objects)
	g++ -DBOOST_LOG_DYN_LINK $(LIB_PATH_4LINK) -o $@ $^ $(LIBS_4LINK2) $(CFLAGS)
#$(GCPP) $(LIB_PATH_4LINK) -o $@ $^ $(LIBS_4LINK3) $(CFLAGS) -D_GLIBCXX_DEBUG /usr/local/include/boost/lib/libboost_log.a -lstdc++ #-Wsign-compare -DBOOST_ALL_DYN_LINK $(INCLUDEFlags) 

$(OBJ_PATH)/%_c.o : $(SRC_PATH)/%.c
	$(GCPP) -DBOOST_LOG_DYN_LINK $(CFLAGS) -c $< -o $@
	
$(OBJ_PATH)/%_cpp.o : $(SRC_PATH)/%.cpp
	g++ -DBOOST_LOG_DYN_LINK $(CFLAGS) -c $< -o $@

#$(OBJ_PATH)/redis_ccpp.o : $(SRC_PATH)/redis.h
#	g++ -DBOOST_LOG_DYN_LINK $(CFLAGS) -c $< -o $@


.PHONY:clean
clean:
	$(RM) $(Objects)
	$(RM) $(EXE_PATH)/$(TARGET)
